<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Hoodoo::ActiveRecord::Finder::SearchHelper</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        <h1>
            <span class="type">Class</span>
            Hoodoo::ActiveRecord::Finder::SearchHelper
                <span class="parent">&lt;
                    Object
                </span>
        </h1>
        <ul class="files">
            <li><a href="../../../../files/lib/hoodoo/active/active_record/search_helper_rb.html">lib/hoodoo/active/active_record/search_helper.rb</a></li>
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
    <div class="description">
      
<p>Help build up Hash maps to pass into <a
href="../Finder.html">Hoodoo::ActiveRecord::Finder</a> methods
Hoodoo::ActiveRecord::Finder#search_with and
Hoodoo::ActiveRecord::Finder#filter_with.</p>

<p>The usage pattern is as follows, using “sh” as a local variable just for
brevity - it isn&#39;t required:</p>

<pre><code>sh = Hoodoo::ActiveRecord::Finder::SearchHelper

class SomeModel &lt; ActiveRecord::Base
  search_with(
    :colour       =&gt; sh.cs_match_generic,
    :name         =&gt; sh.ci_match_generic,
    :resource_ids =&gt; sh.cs_match_csv( :associated_id )
  end
end</code></pre>

<p>The helper methods just provide values to pass into the Hash used with the
search/fitler <a href="../Finder.html">Hoodoo::ActiveRecord::Finder</a>
methods, so they&#39;re optional and compatible with calls that write it
out “by hand”.</p>

<p>In all cases, in normal use the generated SQL _will not_ match
<code>null</code> values; if negated for a filter
(“<code>where.not</code>”), the generated SQL <em>will</em> match
<code>null</code> values. As a result, passing in explicit searches for
<code>nil</code> won&#39;t work - but that&#39;s never expected as a use
case here since search values are coming in via e.g. query string
information from a URI.</p>

    </div>








    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
        <dt>C</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-c-ci_match_generic">ci_match_generic</a>,
              </li>
              <li>
                <a href="#method-c-ci_match_postgres">ci_match_postgres</a>,
              </li>
              <li>
                <a href="#method-c-ciaw_match_generic">ciaw_match_generic</a>,
              </li>
              <li>
                <a href="#method-c-ciaw_match_postgres">ciaw_match_postgres</a>,
              </li>
              <li>
                <a href="#method-c-cs_match">cs_match</a>,
              </li>
              <li>
                <a href="#method-c-cs_match_array">cs_match_array</a>,
              </li>
              <li>
                <a href="#method-c-cs_match_csv">cs_match_csv</a>,
              </li>
              <li>
                <a href="#method-c-csaw_match">csaw_match</a>
              </li>
          </ul>
        </dd>
    </dl>










    <!-- Methods -->
      <div class="sectiontitle">Class Public methods</div>
        <div class="method">
          <div class="title method-title" id="method-c-ci_match_generic">
              <b>ci_match_generic</b>( model_field_name = nil )
            <a href="../../../../classes/Hoodoo/ActiveRecord/Finder/SearchHelper.html#method-c-ci_match_generic" name="method-c-ci_match_generic" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Case-insensitive match which should be fairly database independent but will
run relatively slowly as a result. If you are using PostgreSQL, consider
using the faster ci_match_postgres method instead.</p>

<p>Results in a <code>lower(foo) = bar</code> query with <code>bar</code>
coerced to a String and converted to lower case by Ruby first.</p>
<dl class="rdoc-list note-list"><dt><code>model_field_name</code>
<dd>
<p>If the model attribute name differs from the search key you want to use in
the URI, give the model attribute name here, else omit.</p>
</dd></dl>

<p>Returns a value that can be asssigned to a URI query string key in the Hash
given to Hoodoo::ActiveRecord::Finder#search_with or
Hoodoo::ActiveRecord::Finder#filter_with.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-ci_match_generic_source')" id="l_method-c-ci_match_generic_source">show</a>
              </p>
              <div id="method-c-ci_match_generic_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/active/active_record/search_helper.rb, line 144</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">ci_match_generic</span>( <span class="ruby-identifier">model_field_name</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span> <span class="ruby-operator">|</span>
    <span class="ruby-identifier">column</span> = <span class="ruby-identifier">model_field_name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>
    <span class="ruby-identifier">value</span>  = ( <span class="ruby-identifier">value</span> <span class="ruby-operator">||</span> <span class="ruby-string">&#39;&#39;</span> ).<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">downcase</span>

    [ <span class="ruby-node">&quot;lower(#{ column }) = ? AND #{ column } IS NOT NULL&quot;</span>, <span class="ruby-identifier">value</span> ]
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-ci_match_postgres">
              <b>ci_match_postgres</b>( model_field_name = nil )
            <a href="../../../../classes/Hoodoo/ActiveRecord/Finder/SearchHelper.html#method-c-ci_match_postgres" name="method-c-ci_match_postgres" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Case-insensitive match which requires PostgreSQL but should run quickly. If
you need a database agnostic solution, consider using the slower
ci_match_generic method instead.</p>

<p>Results in a <code>foo ILIKE bar</code> query.</p>
<dl class="rdoc-list note-list"><dt><code>model_field_name</code>
<dd>
<p>If the model attribute name differs from the search key you want to use in
the URI, give the model attribute name here, else omit.</p>
</dd></dl>

<p>Returns a value that can be asssigned to a URI query string key in the Hash
given to Hoodoo::ActiveRecord::Finder#search_with or
Hoodoo::ActiveRecord::Finder#filter_with.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-ci_match_postgres_source')" id="l_method-c-ci_match_postgres_source">show</a>
              </p>
              <div id="method-c-ci_match_postgres_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/active/active_record/search_helper.rb, line 179</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">ci_match_postgres</span>( <span class="ruby-identifier">model_field_name</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span> <span class="ruby-operator">|</span>
    <span class="ruby-identifier">column</span> = <span class="ruby-identifier">model_field_name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>

    [ <span class="ruby-node">&quot;#{ column } ILIKE ? AND #{ column } IS NOT NULL&quot;</span>, <span class="ruby-identifier">value</span> ]
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-ciaw_match_generic">
              <b>ciaw_match_generic</b>( model_field_name = nil )
            <a href="../../../../classes/Hoodoo/ActiveRecord/Finder/SearchHelper.html#method-c-ciaw_match_generic" name="method-c-ciaw_match_generic" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>As ci_match_generic, but adds wildcards at the front and end of the string
for a case-insensitive-all-wildcard match.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-ciaw_match_generic_source')" id="l_method-c-ciaw_match_generic_source">show</a>
              </p>
              <div id="method-c-ciaw_match_generic_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/active/active_record/search_helper.rb, line 156</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">ciaw_match_generic</span>( <span class="ruby-identifier">model_field_name</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span> <span class="ruby-operator">|</span>
    <span class="ruby-identifier">column</span> = <span class="ruby-identifier">model_field_name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>
    <span class="ruby-identifier">value</span>  = ( <span class="ruby-identifier">value</span> <span class="ruby-operator">||</span> <span class="ruby-string">&#39;&#39;</span> ).<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">downcase</span>

    [ <span class="ruby-node">&quot;lower(#{ column }) LIKE ? AND #{ column } IS NOT NULL&quot;</span>, <span class="ruby-node">&quot;%#{ value }%&quot;</span> ]
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-ciaw_match_postgres">
              <b>ciaw_match_postgres</b>( model_field_name = nil )
            <a href="../../../../classes/Hoodoo/ActiveRecord/Finder/SearchHelper.html#method-c-ciaw_match_postgres" name="method-c-ciaw_match_postgres" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>As ci_match_postgres, but adds wildcards at the front and end of the string
for a case-insensitive-all-wildcard match.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-ciaw_match_postgres_source')" id="l_method-c-ciaw_match_postgres_source">show</a>
              </p>
              <div id="method-c-ciaw_match_postgres_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/active/active_record/search_helper.rb, line 190</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">ciaw_match_postgres</span>( <span class="ruby-identifier">model_field_name</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span> <span class="ruby-operator">|</span>
    <span class="ruby-identifier">column</span> = <span class="ruby-identifier">model_field_name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>

    [ <span class="ruby-node">&quot;#{ column } ILIKE ? AND #{ column } IS NOT NULL&quot;</span>, <span class="ruby-node">&quot;%#{ value }%&quot;</span> ]
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-cs_match">
              <b>cs_match</b>( model_field_name = nil )
            <a href="../../../../classes/Hoodoo/ActiveRecord/Finder/SearchHelper.html#method-c-cs_match" name="method-c-cs_match" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Case-sensitive match (default-style matching). <strong>WARNING:</strong>
This will be case sensitive only if your database is configured for case
sensitive matching by default.</p>

<p>Results in a <code>foo = bar</code> query.</p>
<dl class="rdoc-list note-list"><dt><code>model_field_name</code>
<dd>
<p>If the model attribute name differs from the search key you want to use in
the URI, give the model attribute name here, else omit.</p>
</dd></dl>

<p>Returns a value that can be asssigned to a URI query string key in the Hash
given to Hoodoo::ActiveRecord::Finder#search_with or
Hoodoo::ActiveRecord::Finder#filter_with.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-cs_match_source')" id="l_method-c-cs_match_source">show</a>
              </p>
              <div id="method-c-cs_match_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/active/active_record/search_helper.rb, line 61</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">cs_match</span>( <span class="ruby-identifier">model_field_name</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span> <span class="ruby-operator">|</span>
    <span class="ruby-identifier">column</span> = <span class="ruby-identifier">model_field_name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>

    [ <span class="ruby-node">&quot;#{ column } = ? AND #{ column } IS NOT NULL&quot;</span>, <span class="ruby-identifier">value</span> ]
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-cs_match_array">
              <b>cs_match_array</b>( model_field_name = nil )
            <a href="../../../../classes/Hoodoo/ActiveRecord/Finder/SearchHelper.html#method-c-cs_match_array" name="method-c-cs_match_array" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Case-sensitive match of a series of values given as an Array. Normally,
query string information comes in as a String so the use cases for this are
quite unusual; you probably want to use cs_match_csv most of the time.</p>

<p>Results in a <code>foo IN bar,baz,boo</code> query.</p>
<dl class="rdoc-list note-list"><dt><code>model_field_name</code>
<dd>
<p>If the model attribute name differs from the search key you want to use in
the URI, give the model attribute name here, else omit.</p>
</dd></dl>

<p>Returns a value that can be asssigned to a URI query string key in the Hash
given to Hoodoo::ActiveRecord::Finder#search_with or
Hoodoo::ActiveRecord::Finder#filter_with.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-cs_match_array_source')" id="l_method-c-cs_match_array_source">show</a>
              </p>
              <div id="method-c-cs_match_array_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/active/active_record/search_helper.rb, line 107</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">cs_match_array</span>( <span class="ruby-identifier">model_field_name</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span> <span class="ruby-operator">|</span>
    <span class="ruby-identifier">column</span> = <span class="ruby-identifier">model_field_name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>
    <span class="ruby-identifier">value</span>  = [ <span class="ruby-identifier">value</span> ].<span class="ruby-identifier">flatten</span>

    [ <span class="ruby-node">&quot;#{ column } IN (?) AND #{ column } IS NOT NULL&quot;</span>, <span class="ruby-identifier">value</span> ]
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-cs_match_csv">
              <b>cs_match_csv</b>( model_field_name = nil )
            <a href="../../../../classes/Hoodoo/ActiveRecord/Finder/SearchHelper.html#method-c-cs_match_csv" name="method-c-cs_match_csv" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Case-sensitive match of a series of values separated by commas, which are
split into an array then processed by AREL back to something SQL-safe.</p>

<p>Results in a <code>foo IN bar,baz,boo</code> query.</p>
<dl class="rdoc-list note-list"><dt><code>model_field_name</code>
<dd>
<p>If the model attribute name differs from the search key you want to use in
the URI, give the model attribute name here, else omit.</p>
</dd></dl>

<p>Returns a value that can be asssigned to a URI query string key in the Hash
given to Hoodoo::ActiveRecord::Finder#search_with or
Hoodoo::ActiveRecord::Finder#filter_with.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-cs_match_csv_source')" id="l_method-c-cs_match_csv_source">show</a>
              </p>
              <div id="method-c-cs_match_csv_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/active/active_record/search_helper.rb, line 83</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">cs_match_csv</span>( <span class="ruby-identifier">model_field_name</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span> <span class="ruby-operator">|</span>
    <span class="ruby-identifier">column</span> = <span class="ruby-identifier">model_field_name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>
    <span class="ruby-identifier">value</span>  = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">split</span>( <span class="ruby-string">&#39;,&#39;</span> )

    [ <span class="ruby-node">&quot;#{ column } IN (?) AND #{ column } IS NOT NULL&quot;</span>, <span class="ruby-identifier">value</span> ]
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-c-csaw_match">
              <b>csaw_match</b>( model_field_name = nil )
            <a href="../../../../classes/Hoodoo/ActiveRecord/Finder/SearchHelper.html#method-c-csaw_match" name="method-c-csaw_match" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>As cs_match, but adds wildcards at the front and end of the string for a
case-sensitive-all-wildcard match.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-csaw_match_source')" id="l_method-c-csaw_match_source">show</a>
              </p>
              <div id="method-c-csaw_match_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/active/active_record/search_helper.rb, line 119</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">csaw_match</span>( <span class="ruby-identifier">model_field_name</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">value</span> <span class="ruby-operator">|</span>
    <span class="ruby-identifier">column</span> = <span class="ruby-identifier">model_field_name</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">attr</span>
    <span class="ruby-identifier">value</span>  = ( <span class="ruby-identifier">value</span> <span class="ruby-operator">||</span> <span class="ruby-string">&#39;&#39;</span> ).<span class="ruby-identifier">to_s</span>

    [ <span class="ruby-node">&quot;#{ column } LIKE ? AND #{ column } IS NOT NULL&quot;</span>, <span class="ruby-node">&quot;%#{ value }%&quot;</span> ]
  }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
</div>

    </div>
  </body>
</html>
